package com.scrawler.yuqing.test.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.scrawler.main.InitProject;
import com.scrawler.regex.template.CrawlArticleContent;
import com.scrawler.vo.NewsContent;
import com.scrawler.vo.NewsContentConfig;

/**
 * Servlet implementation class ArticleContentServlet
 */
public class ArticleContentServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
	
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ArticleContentServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		this.doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		InitProject.init();
		CrawlArticleContent stask = new CrawlArticleContent();

		NewsContentConfig config = new NewsContentConfig();
		config.setTitle(request.getParameter("titile"));
		config.setAuthor(request.getParameter("author"));
		config.setComments(request.getParameter("comment"));
		config.setEncoding(request.getParameter("enconding"));
		config.setPub_time(request.getParameter("pubTime"));
		config.setHits(request.getParameter("hits"));
		config.setContent(request.getParameter("content"));
		
		String url = request.getParameter("url");
		stask.init(url, config);
		NewsContent content = stask.fetchData();
		System.out.println(content.getTitle());
	}

}
